package com.fyw.xmcamera.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.fyw.xmcamera.R;
import com.lib.funsdk.support.models.FunDevice;

import java.util.List;

/**
 * Created by FYW on 2017/10/18.
 */

public class LanListAdapter extends BaseAdapter {
    private Context context;
    private List<FunDevice> list;

    public LanListAdapter(Context context, List<FunDevice> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.item_lan_lv, null);
            viewHolder = new ViewHolder();
            viewHolder.itemMainImg = view.findViewById(R.id.itemMainImg);
            viewHolder.itemMainName = view.findViewById(R.id.itemMainName);
            viewHolder.itemMainView = view.findViewById(R.id.itemMainView);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        FunDevice funDevice = list.get(i);
        viewHolder.itemMainName.setText(funDevice.getDevName() + "\n\n" + funDevice.devType.getDrawableResId());

        viewHolder.itemMainImg.setImageResource(funDevice.devType.getDrawableResId());

        if (list.size() == i + 1)
            viewHolder.itemMainView.setVisibility(View.INVISIBLE);
        else
            viewHolder.itemMainView.setVisibility(View.VISIBLE);
        return view;
    }

    class ViewHolder {
        TextView itemMainName;
        ImageView itemMainImg;
        View itemMainView;
    }
}
